home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / js / server_privileges.js < prev    next >
Encoding:
JavaScript  |  2007-12-20  |  3.1 KB  |  101 lines

  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3.  * function used in server privilege pages
  4.  *
  5.  * @version $Id: server_privileges.js 10929 2007-11-15 17:51:46Z lem9 $
  6.  */
  7.  
  8. /**
  9.  * Validates the password field in a form
  10.  *
  11.  * @param   object   the form
  12.  *
  13.  * @return  boolean  whether the field value is valid or not
  14.  */
  15. function checkPassword(the_form)
  16. {
  17.     // Did the user select 'no password'?
  18.     if (typeof(the_form.elements['nopass']) != 'undefined' && the_form.elements['nopass'][0].checked) {
  19.         return true;
  20.     } else if (typeof(the_form.elements['pred_password']) != 'undefined' && (the_form.elements['pred_password'].value == 'none' || the_form.elements['pred_password'].value == 'keep')) {
  21.         return true;
  22.     }
  23.  
  24.     // Validates
  25.     if (the_form.elements['pma_pw'].value == '') {
  26.         alert(jsPasswordEmpty);
  27.         the_form.elements['pma_pw2'].value = '';
  28.         the_form.elements['pma_pw'].focus();
  29.         return false;
  30.     } else if (the_form.elements['pma_pw'].value != the_form.elements['pma_pw2'].value) {
  31.         alert(jsPasswordNotSame);
  32.         the_form.elements['pma_pw'].value  = '';
  33.         the_form.elements['pma_pw2'].value = '';
  34.         the_form.elements['pma_pw'].focus();
  35.         return false;
  36.     } // end if...else if
  37.  
  38.     return true;
  39. } // end of the 'checkPassword()' function
  40.  
  41.  
  42. /**
  43.  * Validates the "add a user" form
  44.  *
  45.  * @return  boolean  whether the form is validated or not
  46.  */
  47. function checkAddUser(the_form)
  48. {
  49.     if (the_form.elements['pred_hostname'].value == 'userdefined' && the_form.elements['hostname'].value == '') {
  50.         alert(jsHostEmpty);
  51.         the_form.elements['hostname'].focus();
  52.         return false;
  53.     }
  54.  
  55.     if (the_form.elements['pred_username'].value == 'userdefined' && the_form.elements['username'].value == '') {
  56.         alert(jsUserEmpty);
  57.         the_form.elements['username'].focus();
  58.         return false;
  59.     }
  60.  
  61.     return checkPassword(the_form);
  62. } // end of the 'checkAddUser()' function
  63.  
  64.  
  65. /**
  66.  * Generate a new password, which may then be copied to the form
  67.  * with suggestPasswordCopy().
  68.  *
  69.  * @param   string   the form name
  70.  *
  71.  * @return  boolean  always true
  72.  */
  73. function suggestPassword() {
  74.     // restrict the password to just letters and numbers to avoid problems:
  75.     // "editors and viewers regard the password as multiple words and
  76.     // things like double click no longer work"
  77.     var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
  78.     var passwordlength = 16;    // do we want that to be dynamic?  no, keep it simple :)
  79.     var passwd = document.getElementById('generated_pw');
  80.     passwd.value = '';
  81.  
  82.     for ( i = 0; i < passwordlength; i++ ) {
  83.         passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
  84.     }
  85.     return passwd.value;
  86. }
  87.  
  88.  
  89. /**
  90.  * Copy the generated password (or anything in the field) to the form
  91.  *
  92.  * @param   string   the form name
  93.  *
  94.  * @return  boolean  always true
  95.  */
  96. function suggestPasswordCopy() {
  97.     document.getElementById('text_pma_pw').value = document.getElementById('generated_pw').value;
  98.     document.getElementById('text_pma_pw2').value = document.getElementById('generated_pw').value;
  99.     return true;
  100. }
  101.